package cn.tedu.charging.device.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * redis配置类
 */
@Configuration
public class RedisConfiguration {

    @Bean
    //public RedisTemplate<String, Serializable>
    public RedisTemplate
    redisTemplate(RedisConnectionFactory factory){
        RedisTemplate redisTemplate = new RedisTemplate<>();
        //设置连接工厂
        redisTemplate.setConnectionFactory(factory);
        //设置key序列化器
        redisTemplate.setKeySerializer(RedisSerializer.string());
        //设置value序列化器
        redisTemplate.setValueSerializer(RedisSerializer.json());
        return redisTemplate;
    }
}
